import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class JsonFileProcess {
    public JSONObject getJsonObject(String jsonFilePath){
        JSONObject jsonObject = new JSONObject();

        try {
            // 读取JSON文件
            BufferedReader reader = new BufferedReader(new FileReader(jsonFilePath));
            StringBuilder jsonBuilder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                jsonBuilder.append(line);
            }
            reader.close();

            // 解析JSON数据
            String jsonData = jsonBuilder.toString();
            JSONTokener tokeNer = new JSONTokener(jsonData);
            jsonObject = new JSONObject(tokeNer);

            System.out.println("成功读取并解析JSON文件：" + jsonFilePath);
        } catch (IOException e) {
            System.out.println("读取JSON文件时发生错误：" + e.getMessage());
        }

        return jsonObject;
    }
}
